package com.ygqh.baby.controller.mobile;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.ResponseEntity;
import com.ygqh.baby.model.YgProduct4ListModel;
import com.ygqh.baby.service.YgProductSecondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/app/productsecond")
public class YgProductSecondController extends BaseController {

    @Autowired
    private YgProductSecondService ygProductSecondService;

    /**
     * 获取指定日期秒杀商品信息
     *
     * @param specifyDate 指定日期（不指定时，默认为当前日期）
     * @return
     */
    @RequestMapping("findProductListBySecond")
    @ResponseBody
    public ResponseEntity findProductListBySecond(Date specifyDate) {
        List<YgProduct4ListModel> findBySpecifyDate =
                ygProductSecondService.findBySpecifyDate(specifyDate, SALES_PLATFORM);
        return ResponseEntity.success(findBySpecifyDate);
    }

    /**
     * 获取指定商品的秒杀日期
     *
     * @param productId
     * @return
     */
    @RequestMapping("findSecondDateByProductId")
    @ResponseBody
    public ResponseEntity findSecondDateByProductId(Long productId) {
        Message message = ygProductSecondService.findUnEndByPid(productId);
        return ResponseEntity.converter(message);
    }

    /**
     * 当前秒杀活动信息
     *
     * @return
     */
    @RequestMapping("activeSecondInfo")
    @ResponseBody
    public ResponseEntity activeSecondInfo() {
        Map<String, Object> dataMap = ygProductSecondService.findActiveSecondInfo(SALES_PLATFORM);
        return ResponseEntity.success(dataMap);
    }
}
